package utils

import grails.async.PromiseList
import grails.plugins.rest.client.RestBuilder

final class ConfigHelper {

    static final ConfigUri = "http://localhost:4444"

    static boolean refresh(Collection<String> appCtxIds) {
        try {
            def rest = new RestBuilder(), tasks = new PromiseList()

            appCtxIds.each { appCtxId ->
                tasks << {
                    rest.post("$ConfigUri/actuator/bus-refresh/$appCtxId") {
                        contentType "application/json;charset=UTF-8"
//                        header "Authorization", "Bearer $bearerToken"
                    }.status
                }
            }

            tasks.get().findAll { status -> status != 204 }.size() == 0
        } catch (Exception ex) {
            System.err.println ex.message
            false
        }
    }
}
